package part10.controller;

/**
 * @author wcj
 * @Date 2021/5/19 19:46
 * @Version 1.0
 */
public class GreenHouseControls extends Controller {

    private boolean light = false;

    public class LightOn extends BaseEvent {
        public LightOn(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            light = true;
        }

        @Override
        public String toString() {
            return "light is on";
        }
    }

    public class LightOff extends BaseEvent {

        public LightOff(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            light = false;
        }

        @Override
        public String toString() {
            return "light is true";
        }
    }

    private boolean water = false;

    public class WaterOn extends BaseEvent {

        public WaterOn(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            water = true;
        }

        @Override
        public String toString() {
            return "water is on";
        }
    }

    public class WaterOff extends BaseEvent {

        public WaterOff(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            water = false;
        }

        @Override
        public String toString() {
            return "water is false";
        }
    }

    public String thermostat = "Day";

    public class ThermostatNight extends BaseEvent {

        public ThermostatNight(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            thermostat = "Night";
        }

        @Override
        public String toString() {
            return "Thermostat on night setting";
        }
    }

    public class ThermostatDay extends BaseEvent {

        public ThermostatDay(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            thermostat = "Day";
        }

        @Override
        public String toString() {
            return "Thermostat on day setting";
        }
    }

    public class Bell extends BaseEvent {

        public Bell(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            addEvent(new Bell(delayTime));
        }

        @Override
        public String toString() {
            return "Bing!";
        }
    }

    public class Restart extends BaseEvent {
        private BaseEvent[] eventList;

        public Restart(long delayTime, BaseEvent[] eventList) {
            super(delayTime);
            this.eventList = eventList;
            for (BaseEvent e : eventList) {
                addEvent(e);
            }
        }

        @Override
        public void action() {
            for (BaseEvent e : eventList) {
                addEvent(e);
            }
            start();
            addEvent(this);
        }

        @Override
        public String toString() {
            return "Restarting system";
        }
    }

    public static class Terminate extends BaseEvent {

        public Terminate(long delayTime) {
            super(delayTime);
        }

        @Override
        public void action() {
            System.exit(0);
        }

        @Override
        public String toString() {
            return "Terminating";
        }
    }
}
